
local quit = 0
local cmds = {}
local http = require("socket.http")
http.TIMEOUT = 10
local m_url = "http://localhost:8080/"

function prMenu()
	print("=== MENU ===")
	print("[1] 请登陆")
	print("[2] 告诉我你的名字")
	print("[3] 退出")
	print(">请输入整数序号：")
end
function prInput()
	io.write("> ")
end

function main()
	prMenu()
	repeat
		quit = quit + 1
		prInput()
		local line = io.read("l")
		local num = tonumber(line)
		if num then
			local func = cmds[num]
			if type(func) == "function" then
				func()
			else
				print("没有对应命令。")
			end
		else
			print("请正确输入整数序号。")
		end

	until(quit == true or quit == 25)
end

function req(cmd)
	cmd = cmd or ""
	local response = http.request(m_url..cmd)
	return response
end

cmds[1] = function ()
	print("你正在登陆")
	local time = os.time()
	print(time * 1000)
	local response = req("login")
	print(response)
end
cmds[2] = function ()
	print("你正在说名字")
	local response = req("")
	print(response)
end
cmds[3] = function ()
	quit = true
	print("拜拜。")
end

main()

